home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: Use of 'htonl' on DEC Alpha 2100 VME server
- Date: Thu, 1 Feb 1996 02:19:13 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9602010119.AA21648@dxmint.cern.ch>
- References: <4eok6v$15do@morse.ukonline.co.uk>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- david.tuson@ukonline.co.uk (Dave T.) writes:
-
- >I am currently developing an application in which several C/Ada models
- >run on a DEC Alpha 2100 VME server which is running DEC Unix. Data
- >produced by these models is used to drive applications running on an
- >SGI Indigo2 by passing the data over an ethernet connection.
- >
- >Prior to passing the data across the network I use the ntohl()
- ^^^^^^^
- I guess you meant htonl() but this doesn't make any difference. Both
- functions should behave identically on Digital UNIX (i.e. revert the byte
- order of a 32-bit integer).
-
- >function to reverse the order of the bytes in each 32 bit word. When
- >I do this I find that the four bytes in memory immediately after those
- >swapped by ntohl are then all set to zero. Can anyone tell me why
- >this happens and how it can be avoided? Thanks.
-
- This is principially impossible: htonl() expects as its argument an
- unsigned int and produces as result another unsigned int. It cannot
- corrupt any byte because it is not passed a pointer.
-
- My guess is that htonl() is a red herring and you're corrupting the
- data yourself, like this:
-
- unsigned long *ptr = buff;
- *ptr = htonl(some_value);
-
- On Digital UNIX this will set to zero the next four bytes, indeed, because
- a long is 8 bytes on that platform and the byte order is little-endian.
- So, the assignment will convert the result returned by htonl() to a 64-bit
- long and store it, which will result in the first 4 bytes set to the value
- returned by htonl() and the next 4 bytes set to zero.
-
- Never assume that a certain type has the same size on every platform.
- On Digital UNIX, int's and long's have different sizes!
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-